<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="/Public/Home/css/common.css" />
<link type="text/css" rel="stylesheet" href="/Public/Home/css/flow.css" />
<script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
<script type="text/javascript" scr="/Public/Home/js/common.js"></script>
<title>登录页</title>
</head>
<body>
<div id="wrap">
<div class="header">
    <ul id="QuickMenu">
        <li class="my_account"><a href="#">Gordon</a><span>你好,欢迎光临！</span></li>
        
    </ul>
          
   
    <div id="nav">
        <ul class="mian_nav">
            <li class="nav_index"><a href="{:U('Index/index')}" title="">首页</a></li>
            
    </div>
</div>
<div id="search">
    <div class="search_con">
       
       
       
    </div>
</div>
<div class="main">
    
    <div class="flowBox">
        <h6><span>商品列表</span></h6>
        <form id="formCart" name="formCart" method="post" action="flow.php">
            <table width="99%" align="center">

                <tr>

<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                    <th>商品名称</th>
                    <th>属性</th>
                    <th>本店价</th>
                    <th>购买数量</th>
                    <th>小计</th>
                    <th>操作</th>
                </tr>
                <tr>
                <volist name="order" id="v">
                <td><input class="ids" type="checkbox" name="id[]" value="{$v.id}" /></td>

                    <td><a href="goods.php?id=1" target="_blank">
                            <img src="{$v.pic}" border="0" width="90" height="90" />
                        </a><br />
                        <a href="goods.php?id=1" target="_blank" class="f6">{$v.gname}</a></td>
                    <td>{$v.attrval}<br /></td>
                    
                    <td class="price">{$v.price}</td>
                    <td><button style="width:15px;" type="button" class="gnumjian">-</button><input type="text" name="goods_number[44]" id="goods_number_44" value="{$v.sum}" size="6" class="inputBg gum" style="text-align:center " onkeydown="showdiv(this)"/><button class="gnumjia" type="button">+</button></td>
                    <td class="sumprice">{$v.sumprice}</td>
                    <td><a href="javascript:if (confirm('您确实要把该商品移出购物车吗？')) location.href='flow.php?step=drop_goods&amp;id=44'; " class="red_a">删除</a></td>
                </tr>
                </volist>
            </table>
            <table width="99%" align="center" border="0" cellpadding="5" cellspacing="1" bgcolor="#dddddd">
                <tr>
                    <td class="align_left"> 购物金额小计 <span class="color2 zumprice">{$sumprice}</span></td>
                    <td class="align_left">结算小计<span class="color2 jieprice">0
                    </span></td>
                    <td class="align_right"><input type="button" value="清空购物车" class="bnt_blue_1" onclick="location.href='flow.php?step=clear'" />
                        </td>
                </tr>
            </table>
            <input type="hidden" name="step" value="update_cart" />
        </form>
        <div class="operation"> <span class="continue_btn"><a href="{:U('Index/index')}"><img scr="/Public/Home/images/cart_btn1.jpg" alt="继续购物" /></a></span><span class="continue_btn jiesuan"> <button type="button">去结算</button></span>
         </div>
    </div>
</div>

</div>
</body>
</html>
<script type="text/javascript">
// 选择框
$(".check-all").click( 
function(){ 
if(this.checked){ 
$(".ids").each(function(){this.checked=true;});
var zumprice = $('.zumprice').html();
$('.jieprice').html(zumprice); 
}else{ 
$(".ids").each(function(){this.checked=false;});
$('.jieprice').html(0);  
} 
} 
);
//勾选价
$(".ids").change(function(){
    var index = $('.ids').index($(this));
    var djiesuanprice = Number($('.jieprice').html());
    var sumprice = Number($('.sumprice').eq(index).html());
    if ($('.ids').eq(index).is(':checked')) {
        
                    var jieprice = djiesuanprice + sumprice;    
            }else{
                
                    var jieprice = djiesuanprice - sumprice;
            } 
       $('.jieprice').html(jieprice);
});

$(".gnumjia").click(function(){
    var index = $('.gnumjia').index($(this));
    // alert(index);
    var sum =Number($(".gum").eq(index).val());
    var id =$('.ids').eq(index).val();
    // alert(id);
    var gsum =sum+1;
    var price = Number($('.price').eq(index).html());
    var sumprice = price * gsum;
    var zumprice = Number($('.zumprice').html());
    
    
        // alert(111);
    $.post("{:U('Cart/update')}", { id:id, sum:gsum, sumprice:sumprice },
        // alert(111);
            function(data){   
                if(data.status==1){
        if ($('.ids').eq(index).is(':checked')) {
         var cartprice = Number($('.jieprice').html());
         $('.jieprice').html(cartprice+price);
        }
                    $('.zumprice').html(zumprice+price);
                    $('.gum').eq(index).val(gsum);
                    $('.sumprice').eq(index).html(sumprice);
                }
                
            }); 
});

$(".gnumjian").click(function(){
   var index = $('.gnumjian').index($(this));
   var id =$('.ids').eq(index).val();
   var sum =Number($(".gum").eq(index).val());
if (sum==1) {
     alert('购买数量是1的正整数倍');
    }else{
        var gsum =sum-1;
        var price = Number($('.price').eq(index).html());
        var sumprice = price * gsum;
        var zumprice = Number($('.zumprice').html());
    
          $.post("{:U('Cart/update')}", { id:id, sum:gsum, sumprice:sumprice },
        // alert(111);
            function(data){   
                if(data.status==1){
        if ($('.ids').eq(index).is(':checked')) {
         var cartprice = Number($('.jieprice').html());
         $('.jieprice').html(cartprice-price);
        }
                    $('.zumprice').html(zumprice-price);
                    $('.gum').eq(index).val(gsum);
                    $('.sumprice').eq(index).html(sumprice);
                }
                
            }); 
    
    }  

});

$(".gum").keyup(function(){
    var index = $('.gum').index($(this));
    var sum = Number($(".gum").eq(index).val());
    var price = Number($('.price').eq(index).html());
    var sprice = Number($('.sumprice').eq(index).html());
    var sumprice = price * sum;
    var r = /^[0-9]*[1-9][0-9]*$/
    var zumprice = Number($('.zumprice').html());
    var id =$('.ids').eq(index).val();
    if(!r.test(sum)){
        alert('购买数量是1的正整数倍');
        $('.gum').val(1);
        $('.price').html(price);
        $('.zumprice').html(zumprice-sprice+sumprice);
    }else{
        
         $.post("{:U('Cart/update')}", { id:id, sum:sum, sumprice:sumprice },
            function(data){   
                if(data.status==1){
                    if ($(".ids").eq(index).is(':checked')) {
         var cartprice = Number($('.jieprice').html());
         $('.jieprice').html(cartprice-sprice+sumprice);
        }
                    $('.sumprice').eq(index).html(sumprice); 
                    $('.zumprice').html(zumprice-sprice+sumprice); 
                }
                
            });
            
 }  
 })
$('.jiesuan').click(function(){
    // alert(111);
    id_array = new Array();
    $("input[type='checkbox']:checked").each(function(){
        id_array.push($(this).val());//向数组中添加元素
    });
    // alert(id_array);
    var idstr=id_array.join(',');//将数组元素连接起来以构建一个字符串  
                
                if(idstr==null||idstr==""){
                    alert('请选择商品');
                }else{
            
                window.location.href = '{:U('Order/index')}'+'?oid='+idstr;

                }   
})

</script>>